﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JsonServer.FYPDataSetTableAdapters;

namespace JsonServer
{
    public partial class Day : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        int datacount = 0;
        protected void ButtonCalculateDayPower_Click(object sender, EventArgs e)
        {
            string year = this.TextBoxOfDayPageYear.Text;
            string month = this.TextBoxOfDayPageMonth.Text;
            string day = this.TextBoxOfDayPageDay.Text;
            double totalOneDayPower = (Convert.ToDouble(GetOneDayPower(year, month, day)) / 3600);
            string formatedTotalPower = totalOneDayPower.ToString("#.###");
            this.LabelDayPower.Text = "Total one day power is " + formatedTotalPower + "kWh.";
        }

        public string GetOneDayPower(string year, string month, string day)
        {
            // lookup person with the requested id 
            FYPPowerTableTableAdapter adap = new FYPPowerTableTableAdapter();
            var powerTable = adap.GetDataByDay(year, month, day);
            double DayPower = 0;

            foreach (var item in powerTable)
            {
                double eachPower = Convert.ToDouble(item.Power);
                DayPower += eachPower;
                datacount++;
            }
            string sDayPower = DayPower.ToString("#.###0");
            return sDayPower;
        }

    }
}